import Vue from 'vue';
import Vuex from 'vuex';
import state from './state'
import createLogger from 'vuex/dist/logger'

//全局引用
Vue.use(Vuex)

const debug = process.env.NODE_ENV!=='production'

const store = new Vuex.Store({
	state,
	getters:{
		getCount:(state)=>{
			return state.count = state.count<10?"0"+state.count:state.count
		},
		getTid:(state)=>{
			let partitionList=window.__INITIAL_STATE__.reduxAsyncConnect.partitionList
			const hasCon=partitionList[state.curTid]
				if(!hasCon){
					const keyArr = Object.keys(partitionList)
					for(let i=0,len=keyArr.length;i<len;i++){
						const tmpArr = partitionList[keyArr[i]]
						for(let j=0;j<tmpArr.length;j++){
							if(tmpArr[j].tid==state.curTid){
								return state.curTid = keyArr[i]
							}
						}
					}
			}else{
				return state.curTid
			}
		}
	},
	mutations:{
		increment(state){
			state.count++;
		},
		setTid(state,payload){
//			console.log(payload)
			state.curTid=payload.curTid
		},
	},
//	plugins:debug?[createLogger()]:[]
})

export default store
